package net.phoenix.repository.data;

import java.util.ArrayList;
import java.util.List;

import javax.jcr.PropertyType;

/**
 * Jigsaw server
 * <p>
 * net.phoenix.repository.data
 * </p>
 * <p>
 * PropertyDefinitionData
 * </p>
 * 
 * @author <a href="shamphone@gmail.com">Li XiongFeng</a>
 * @date 2011-11-25
 * @version 1.0.0
 */
public class PropertyDefinitionData extends ItemDefinitionData {
	/**
	 * 
	 */
	private static final long serialVersionUID = 3401792926834245120L;
	private int type; // 1表示字符串，10表示clob之类
	private List<String> defaultValues = new ArrayList<String>();
	private boolean multiple=false; // 表示是否为多值属性
	private int minLength=1; // 当为多值属性的时候，表示最少可以有的值
	private int maxLength=1; // 当为多值属性的时候，表示最多可以有的值
	private int orderNo=0; // 序号
	private String description; //
	private boolean deletable=true; // 是否可以删除

	private boolean readOnly=false;// 属性值是否是继承自父结点的
	private boolean required=false;

	private boolean searchable;
	private boolean orderable;

	public PropertyDefinitionData() {
		this.minLength = 1;
		this.maxLength = 1;
		this.description = null;
		this.searchable = true;
		this.orderable = true;
	}

	/**
	 * @return the typeName
	 */
	public String getTypeName() {
		return PropertyType.nameFromValue(type);
	}

	/**
	 * @param typeName
	 *            the typeName to set
	 */
	public void setTypeName(String typeName) {
		this.type = PropertyType.valueFromName(typeName);
	}

	// public void setType(int type) {
	// this.type = type;
	// }
	//
	public int getType() {
		return type;
	}

	/**
	 * @return the defaultValues
	 */
	public String[] getDefaultValues() {
		return defaultValues.toArray(new String[defaultValues.size()]);
	}

	/**
	 * @param defaultValues
	 *            the defaultValues to set
	 */
	public void addDefaultValue(String defaultValue) {
		this.defaultValues.add(defaultValue);
	}

	/**
	 * @return the required
	 */
	public boolean isRequired() {
		return required;
	}

	/**
	 * @param required
	 *            the required to set
	 */
	public void setRequired(boolean required) {
		this.required = required;
	}

	public void setMultiple(boolean multiple) {
		this.multiple = multiple;
	}

	public void setMinLength(int minLength) {
		this.minLength = minLength;
	}

	public void setMaxLength(int maxLength) {
		this.maxLength = maxLength;
	}

	public void setOrderNo(int orderNo) {
		this.orderNo = orderNo;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public void setDeletable(boolean deletable) {
		this.deletable = deletable;
	}

	public void setReadOnly(boolean readOnly) {
		this.readOnly = readOnly;
	}

	public boolean isMultiple() {
		return multiple;
	}

	public int getMinLength() {
		return minLength;
	}

	public int getMaxLength() {
		return maxLength;
	}

	public int getOrderNo() {
		return orderNo;
	}

	public String getDescription() {
		return description;
	}

	public boolean isDeletable() {
		return deletable;
	}

	public boolean isReadOnly() {
		return readOnly;
	}

	public boolean isSearchable() {
		return searchable;
	}

	public void setSearchable(boolean searchable) {
		this.searchable = searchable;
	}

	public boolean isOrderable() {
		return orderable;
	}

	public void setOrderable(boolean orderable) {
		this.orderable = orderable;
	}
}
